package edu.uvic.TabViz.framework.primitives;

import java.io.Serializable;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;

public class Object3DSerialized implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4187884808488712043L;
	float[] vertices;
	float[] normals;
	float[] colors;
	float[] textures;
	short[] indices;
	float[] accRotation;
	boolean transparent;
	Point3D scale, position, rotation;
	String material;
	protected ArrayList<Object3DSerialized> objects;
	boolean visible, touch;
	Light light;
	
	public Object3DSerialized(FloatBuffer vertexBuffer,
			FloatBuffer normalBuffer, FloatBuffer colorBuffer, FloatBuffer TextureBuffer,
			ShortBuffer indexBuffer, Point3D scale, Point3D position,
			Point3D rotation, Material material, boolean transparent,
			ArrayList<Object3D> objectNodes, boolean visible, Light light, float[] accRotation,
			boolean touch) {
		int i;
		this.touch = touch;
		vertices = new float[vertexBuffer.capacity()];
		for (i = 0; i < vertexBuffer.capacity(); i++)
			vertices[i] = vertexBuffer.get(i);
		
		normals = new float[normalBuffer.capacity()];
		for (i = 0; i < normalBuffer.capacity(); i++)
			normals[i] = normalBuffer.get(i);
		
		colors = new float[colorBuffer.capacity()];
		for (i = 0; i < colorBuffer.capacity(); i++)
			colors[i] = colorBuffer.get(i);
		
		textures = new float[TextureBuffer.capacity()];
		for (i = 0; i < TextureBuffer.capacity(); i++)
			textures[i] = TextureBuffer.get(i);
		
		indices = new short[indexBuffer.capacity()];
		for (i = 0; i < indexBuffer.capacity(); i++)
			indices[i] = indexBuffer.get(i);
		this.scale = new Point3D(scale);
		this.position = new Point3D(position);
		this.rotation = new Point3D(rotation);
		this.accRotation = accRotation;
		if(material != null)
			this.material = material.getClass().getName();
		
		this.transparent = transparent;
		this.visible = visible;
		
		if(light != null)
			this.light = new Light(light);
		
		objects = new ArrayList<Object3DSerialized>();
		
		for( Object3D o : objectNodes)
			objects.add(o.serialize());
	}
	public float[] getVertices() {
		return vertices;
	}
	public void setVertices(float[] vertices) {
		this.vertices = vertices;
	}
	public float[] getNormals() {
		return normals;
	}
	public void setNormals(float[] normals) {
		this.normals = normals;
	}
	public float[] getColors() {
		return colors;
	}
	public void setColors(float[] colors) {
		this.colors = colors;
	}
	public short[] getIndices() {
		return indices;
	}
	public void setIndices(short[] indices) {
		this.indices = indices;
	}
	public boolean isTransparent() {
		return transparent;
	}
	public void setTransparent(boolean transparent) {
		this.transparent = transparent;
	}
	public Point3D getScale() {
		return scale;
	}
	public void setScale(Point3D scale) {
		this.scale = scale;
	}
	public Point3D getPosition() {
		return position;
	}
	public void setPosition(Point3D position) {
		this.position = position;
	}
	public Point3D getRotation() {
		return rotation;
	}
	public void setRotation(Point3D rotation) {
		this.rotation = rotation;
	}
	public String getM() {
		return material;
	}
	public void setM(String material) {
		this.material = material;
	}
	public ArrayList<Object3DSerialized> getObjects() {
		return objects;
	}
	public void setObjects(ArrayList<Object3DSerialized> objects) {
		this.objects = objects;
	}
	public boolean isVisible() {
		return visible;
	}
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	public Light getLight() {
		return light;
	}
	public void setLight(Light light) {
		this.light = light;
	}
	public float[] getTextures() {
		return textures;
	}
	public void setTextures(float[] textures) {
		this.textures = textures;
	}
	public float[] getAccRotation() {
		return accRotation;
	}
	public void setAccRotation(float[] accRotation) {
		this.accRotation = accRotation;
	}
	public String getMaterial() {
		return material;
	}
	public void setMaterial(String material) {
		this.material = material;
	}
	public boolean isTouch() {
		return touch;
	}
	public void setTouch(boolean touch) {
		this.touch = touch;
	}
}
